package cn.jiyun.service.impl;


import cn.jiyun.mapper.BranchMapper;
import cn.jiyun.mapper.ProjectMapper;
import cn.jiyun.page.PageResult;
import cn.jiyun.page.QueryPageBean;
import cn.jiyun.pojo.Branch;
import cn.jiyun.pojo.Project;
import cn.jiyun.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class BranchServiceImpl implements BranchService {
    @Autowired
    private BranchMapper branchMapper;
    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public int add(Branch branch) {
        int add = branchMapper.add(branch);
         return  add;
    }

    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {
        List<Map> list = branchMapper.findAll((queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize(), queryPageBean.getPageSize(),queryPageBean.getQueryString());
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        Long pageSize =branchMapper.getCount();
        pageResult.setTotal(pageSize);
        return new PageResult(pageResult.getTotal(),pageResult.getRows());
    }

    @Override
    public int update(Branch branch) {
        int add = branchMapper.update(branch);
        return  add;
    }

    @Override
    public int delete(Integer did) {
        return branchMapper.delete(did);
    }

    @Override
    public Branch findById(Integer did) {
        return  branchMapper.findById(did);

    }

    @Override
    public List<Project> findProjectList(Integer did) {
        return branchMapper.findProjectList(did);
    }

    @Override
    public List<Project> findProjectList2() {
        return branchMapper.findProjectList2();
    }
}
